
package listeneres;

import basicas.Usuario;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Web application lifecycle listener.
 * @author Diego
 * Esse listener é quem cuida do timeout de 10 min para o usuario responder as perguntas
 * ele é que redireciona o usuario,para a página de fim de jogo.
 */
public class TimeOut implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession sessao = se.getSession();
        Usuario u = (Usuario) sessao.getAttribute("usuario");
        ServletContext contexto = sessao.getServletContext();
        sessao.setMaxInactiveInterval(30*60);
       RequestDispatcher r = contexto.getRequestDispatcher("User/Game Over.jsp");
        
       try {
            r.forward(null, null);
        } catch (ServletException ex) {
            Logger.getLogger(TimeOut.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TimeOut.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
